<?php

require('Models/calendarlib.php');

initCalendar();

function calendarMonth($id,$language,$month,$year)
{

	$calendar_html = "";
	$actual = firstDayTimestamp($month,$year);
	$next = $actual;
	$dayslocated = getDaysLocated(PDO_BDD_Connect(),$id);
	
	$language[$_SESSION['lang']]["calendarhead"] = createDayNames($_SESSION['lang']);
	$language[$_SESSION['lang']]["calendarmonths"] = createMonths($_SESSION['lang']);
	
	$nextValues = getNextYearMonthValues();
	$previousValues = getPreviousYearMonthValues();

	$calendar_html .= makeCalendarTableHead($id,$language,$nextValues,$previousValues,$actual);

	$calendar_html .= previousMonthDaysCases($actual);

	while (inCurrentMonth($actual,$next))
	{
		
		$dayDatas = isLocatedDay($next,$dayslocated);
		
		if (newWeek($next))
		{
			$calendar_html .= newTableLine();
		}
		
		$calendar_html .= createDay($language,$dayDatas,$next);
		
		$next = nextDayTimestamp($next);
		
	}
	
	$calendar_html .= nextMonthDaysCases($next);

	return $calendar_html.'</table></div>';

}

function calendarYear($id,$year)
{
	
	$language[$_SESSION['lang']]["calendarmonths"] = createMonths($_SESSION['lang']);
	
	$calendar_html = '	<div id="calendar"><table id="calendartable">
				<tr>
					<th>
						<form>
							<a href="#calendar" onclick="document.getElementById(\'calendar\').innerHTML = ajaxinclude(\'displaycalendar.php?id='.$id.'&year='.($_GET['year'] - 1).'\');fader(\'calendar\',50,100,500);"><</a>
							<!--<input type="submit" value="<" style="background:none; border:none;"/>
							<input type="hidden" name="id" value="'.$id.'">
							<input type="hidden" name="year" value="'.($_GET['year'] - 1).'">-->
						</form>
					</th>
					<th align="center" colspan="2">'.$_GET['year'].'</th>
					<th>
						<form>
							<a href="#calendar" onclick="document.getElementById(\'calendar\').innerHTML = ajaxinclude(\'displaycalendar.php?id='.$id.'&year='.($_GET['year'] + 1).'\');fader(\'calendar\',50,100,500);">></a>
							<!--<input type="submit" value=">" style="background:none; border:none;"/>
							<input type="hidden" name="id" value="'.$id.'">
							<input type="hidden" name="year" value="'.($_GET['year'] + 1).'">-->
						</form>
					</th>
				</tr>';
	
	$monthnumber = 0;
	foreach ($language[$_SESSION['lang']]["calendarmonths"] as $month)
	{
		$monthnumber ++;
		if (!($monthnumber&1))
		{
		$calendar_html .= '
							
								<td colspan="2">
									<form>
										<a href="#calendar" onclick="document.getElementById(\'calendar\').innerHTML = ajaxinclude(\'displaycalendar.php?id='.$id.'&year='.$_GET['year'].'&month='.$monthnumber.'\');fader(\'calendar\',50,100,500);">'.$month.'</a>
										<!--<input type="submit" value="'.$month.'" style="background:none; border:none;"/>
										<input type="hidden" name="id" value="'.$id.'">
										<input type="hidden" name="year" value="'.$_GET['year'].'">
										<input type="hidden" name="month" value="'.$monthnumber.'">-->
									</form>
								</td>
							</tr>';
		}
		else
		{
			$calendar_html .= '<tr>
								<td colspan="2">
									<form>
										<a href="#calendar" onclick="document.getElementById(\'calendar\').innerHTML = ajaxinclude(\'displaycalendar.php?id='.$id.'&year='.$_GET['year'].'&month='.$monthnumber.'\');fader(\'calendar\',50,100,500);">'.$month.'</a>
										<!--<input type="submit" value="'.$month.'" style="background:none; border:none;"/>
										<input type="hidden" name="id" value="'.$id.'">
										<input type="hidden" name="year" value="'.$_GET['year'].'">
										<input type="hidden" name="month" value="'.$monthnumber.'">-->
									</form>
								</td>';
		}
							
	}
	
	return $calendar_html.'</table></div>';
}
?>
